version: "3"

services:
  mysql:
    container_name: db_mysql
    image: mysql:8.0
    restart: always
    environment:
      MYSQL_DATABASE: "{{= d.name.toLowerCase().replace('-', '_') }}"
      MYSQL_USER: "{{= d.name.toLowerCase().replace('-', '_') }}"
      MYSQL_PASSWORD: "password"
      MYSQL_ROOT_PASSWORD: "password"
      TZ: Asia/Shanghai
    ports:
      - "3306:3306"
    expose:
      - "3306"
    volumes:
      # 挂载mysql数据存储目录为本地
      - ./mysql/data:/var/lib/mysql
      # 启动时mysql需要执行的文件列表
      - ./mysql/init/:/docker-entrypoint-initdb.d/
  {{= d.name }}:
    container_name: {{= d.name }}
    image: {{= d.name }}
    ports:
      - "3000:3000"
    environment:
      # 是否是开发模式
      - CHATGPT_API_DEBUG: False
      # 启动端口
      - CHATGPT_API_PORT: 3000
      # Mysql 连接地址
      - CHATGPT_API_MYSQL_URI: mysql://{{= d.name.toLowerCase().replace('-', '_') }}:x@mysql:3306/{{= d.name.toLowerCase().replace('-', '_') }}
      # Rate Limit
      - CHATGPT_API_MAX_REQUEST_PER_HOUR: 60000
    volumes:
      - ./logs/temp/logs
    links:
      - mysql
  nginx:
    container_name: nginx
    image: nginx:alpine
    ports:
      - "80:80"
    expose:
      - "80"
    volumes:
      - ./nginx/html:/usr/share/nginx/html
      - ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf
    links:
      - {{= d.name }}
